package gwtadmin.client.wsdltree;

import com.google.gwt.user.client.rpc.IsSerializable;

public class QName implements IsSerializable {
	
	public QName() {
		name = null;
		uri = null;
	}
	
	/* format: {uri}name */
	public QName(String un) {
		if (!un.startsWith("{") || un.indexOf('}') == -1) {
			name = un;
			uri = null;
			return;
		}
		
		int end = un.indexOf('}');
		uri = un.substring(1, end);
		name = un.substring(end+1);
	}
	
	public QName(String name, String uri) {
		this.name = name;
		this.uri = uri;
	}
	
	public QName create(String name) {
		return new QName(name, uri);
	}
	
	@Override
	public boolean equals(Object o) {

		if (this == o)
			return true;
		
		if (o instanceof QName) {
			QName q = (QName) o;
			boolean eq1 = ((name == null && q.name == null) || name.equals(q.name));
			boolean eq2 = ((uri == null && q.uri == null) || uri.equals(q.uri));
			return (eq1 && eq2);
		}
		
		return false;
	}
	
	@Override
	public String toString() {
		return "{" + uri + "}" + name;
	}
	
	public String name;
	public String uri;
}
